home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // MovieDialog.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include <Movies.h>
-
-
- //____________________________________________________________
-
- void InitializeAllToolboxes( void );
- void OpenDisplayDialog( void );
- void LoadAndRunMovie( DialogPtr, Str255 );
-
-
- //____________________________________________________________
-
- #define rMovieWindow 128
- #define rMovieDialog 128
- #define kQuitButton 1
- #define kClearButton 2
- #define kApolloButton 3
- #define kVenusButton 4
- #define kFrameButton 5
- #define kMovieFramePicture 128
- #define kFramePixelSize 4
- #define kApolloMovieName "\p:Movie ƒ:Apollo Launch"
- #define kVenusMovieName "\p:Movie ƒ:Venus Probe"
-
-
- //____________________________________________________________
-
- Boolean gAllDone = false;
-
-
- //____________________________________________________________
-
- void main( void )
- {
- InitializeAllToolboxes();
-
- OpenDisplayDialog();
- }
-
-
- //____________________________________________________________
-
- void OpenDisplayDialog( void )
- {
- DialogPtr theDialog;
- short theItem;
- Boolean allDone = false;
- short theType;
- Handle theHandle;
- Rect theRect;
- PicHandle thePicture;
-
- theDialog = GetNewDialog( rMovieDialog, nil, (WindowPtr)-1L );
- ShowWindow( theDialog );
- SetPort( theDialog );
-
- while ( allDone == false )
- {
- ModalDialog( nil, &theItem );
-
- switch ( theItem )
- {
- case kApolloButton:
- LoadAndRunMovie( theDialog, kApolloMovieName );
- break;
-
- case kVenusButton:
- LoadAndRunMovie( theDialog, kVenusMovieName );
- break;
-
- case kClearButton:
- GetDialogItem( theDialog, kFrameButton, &theType, &theHandle, &theRect );
- thePicture = GetPicture( kMovieFramePicture );
- DrawPicture( thePicture, &theRect );
- break;
-
- case kQuitButton:
- allDone = true;
- break;
- }
- }
-
- DisposeDialog( theDialog );
- }
-
-
- //____________________________________________________________
-
- void LoadAndRunMovie( DialogPtr theDialog, Str255 theMovieName )
- {
- OSErr theError;
- FSSpec theFSSpec;
- short theFileRefNum;
- Movie theMovie;
- short theMovieResID = 0;
- Str255 theMovieResName;
- Boolean wasAltered;
- Rect theMovieBox;
- short theType;
- Handle theHandle;
- Rect theRect;
-
- theError = FSMakeFSSpec( 0, 0L, theMovieName, &theFSSpec );
- theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
- theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
- theMovieResName, newMovieActive, &wasAltered );
-
- CloseMovieFile( theFileRefNum );
-
- SetMovieGWorld( theMovie, (CGrafPtr)theDialog, nil);
-
- GetMovieBox( theMovie, &theMovieBox );
- OffsetRect( &theMovieBox, -theMovieBox.left, -theMovieBox.top );
- GetDialogItem( theDialog, kFrameButton,
- &theType, &theHandle, &theRect );
- OffsetRect( &theMovieBox, theRect.left + kFramePixelSize, theRect.top + kFramePixelSize );
- SetMovieBox( theMovie, &theMovieBox );
-
- GoToBeginningOfMovie( theMovie );
-
- StartMovie( theMovie );
-
- do
- {
- MoviesTask(theMovie, 0);
- }
- while ( IsMovieDone( theMovie ) == false );
-
- DisposeMovie( theMovie );
- }
-
-
- //____________________________________________________________
-
- void InitializeAllToolboxes( void )
- {
- OSErr theError;
- long theResult;
-
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
-
- theError = Gestalt( gestaltQuickTime, &theResult );
- if ( theError != noErr )
- ExitToShell();
-
- theError = EnterMovies();
- if ( theError != noErr )
- ExitToShell();
- }
-